﻿
Imports System.Net.Sockets
Imports osi.root.constants
Imports osi.service.commander

Public Class responder
    Inherits commander.responder

    Private Shared Function response_timeout_ms(ByVal p As powerpoint,
                                                ByVal use_response_timeout_ms As Boolean) As Int64
        Return If(p Is Nothing OrElse Not use_response_timeout_ms, npos, p.response_timeout_ms)
    End Function

    'for accepter
    Friend Sub New(ByVal c As TcpClient, ByVal p As powerpoint, ByVal e As executor)
        MyBase.New(False,
                   If(p Is Nothing OrElse c Is Nothing,
                      Nothing,
                      p.as_herald(c)),
                   response_timeout_ms(p, True),
                   e,
                   DirectCast(Nothing, Func(Of Boolean)))
    End Sub

    Public Sub New(ByVal p As powerpoint,
                   ByVal e As executor,
                   Optional ByVal stopping As Func(Of Boolean) = Nothing)
        MyBase.New(p.herald_device_pool,
                   response_timeout_ms(p, False),
                   e,
                   stopping)
    End Sub

    Public Sub New(ByVal name As String,
                   ByVal e As executor,
                   Optional ByVal stopping As Func(Of Boolean) = Nothing)
        Me.New(connection_manager.get(name), e, stopping)
    End Sub
End Class
